package top.hours48.ddbearapi.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Role;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import top.hours48.ddbearapi.handler.AdminHandler;
import top.hours48.ddbearapi.model.PageResult;
import top.hours48.ddbearapi.model.admin.AuthUserMO;
import top.hours48.ddbearapi.model.role.RoleMO;

import java.util.List;
import java.util.Map;


@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/admin")
public class AdminController {

    Logger logger = LoggerFactory.getLogger(AdminController.class);

    @Autowired
    private AdminHandler adminHandler;

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public PageResult<AuthUserMO> menus(
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {

        PageResult users = adminHandler.queryAuthUsers();
        return users;
    }

    @RequestMapping(value = "/role", method = RequestMethod.GET)
    public RoleMO role(int roleId,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {

        RoleMO roleMO = adminHandler.queryUserRole(roleId);
        return roleMO;
    }
}
